//
//  CGResetPasswordViewController.m
//  SchoolClient
//
//  Created by mac on 15/11/3.
//  Copyright © 2015年 mac. All rights reserved.
//

#import "CGResetPasswordViewController.h"

@interface CGResetPasswordViewController ()

@property(nonatomic,strong)UITextField *accountText;            //账号
@property(nonatomic,strong)UITextField *passwordText;           //密码
@property(nonatomic,strong)UIButton *completeButton;            //完成

@property(nonatomic,strong)UIView *shadowView;
@property(nonatomic,strong)UIActivityIndicatorView *activity;
@property(nonatomic,assign)CGFloat textFontSize;

@end

@implementation CGResetPasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"重设密码";
    self.view.backgroundColor = [Tools getColor:@"ebebeb"];
    
    self.textFontSize = 15;
    
    [self layoutUI];
}

-(void)layoutUI{
    
    CGRect aFrame = CGRectMake(20, 30, SCREEN_WIDTH - 20 - 20, 44);
    CGRect bFrame = CGRectMake(60, 35, SCREEN_WIDTH - 40 - 40, 34);
    CGRect cFrame = CGRectMake(30, 42, 20, 20*38/37);
    //账号
    UIImageView *accountView = [[UIImageView alloc]initWithFrame:aFrame];
    accountView.image = [UIImage imageNamed:@"login_input_phone_bg"];
    [self.view addSubview:accountView];
    //输入文本框
    self.accountText = [[UITextField alloc]initWithFrame:bFrame];
    self.accountText.clearButtonMode = UITextFieldViewModeAlways;
    self.accountText.placeholder = @"请输入新密码";
    self.accountText.font = [UIFont systemFontOfSize:self.textFontSize];
    [self.view addSubview:self.accountText];
    //图标
    UIImageView *accountImageView = [[UIImageView alloc]initWithFrame:cFrame];
    accountImageView.image = [UIImage imageNamed:@"login_password_icon"];
    [self.view addSubview:accountImageView];
    
    //密码
    aFrame.origin.y += 60;
    bFrame.origin.y += 60;
    cFrame.origin.y += 60;
    UIImageView *passwordView = [[UIImageView alloc]initWithFrame:aFrame];
    passwordView.image = [UIImage imageNamed:@"login_input_phone_bg"];
    [self.view addSubview:passwordView];
    //输入文本框
    self.passwordText = [[UITextField alloc]initWithFrame:bFrame];
    self.passwordText.clearButtonMode = UITextFieldViewModeAlways;
    self.passwordText.placeholder = @"请再次输入新密码";
    self.passwordText.font = [UIFont systemFontOfSize:self.textFontSize];
    [self.view addSubview:self.passwordText];
    //图标
    //cFrame.size.width = 20*35/42;
    UIImageView *passwordImageView = [[UIImageView alloc]initWithFrame:cFrame];
    passwordImageView.image = [UIImage imageNamed:@"login_password_icon"];
    [self.view addSubview:passwordImageView];
    
    //完成Button
    aFrame.origin.y += 80;
    self.completeButton = [[UIButton alloc]initWithFrame:aFrame];
    [self.completeButton setBackgroundImage:[UIImage imageNamed:@"login_btn_bg"] forState:UIControlStateNormal];
    [self.completeButton setTitle:@"完成" forState:UIControlStateNormal];
    self.completeButton.titleLabel.font = [UIFont boldSystemFontOfSize:18];
    [self.view addSubview:self.completeButton];
    //添加点击事件
    [self.completeButton addTarget:self action:@selector(tapCompleteButton:) forControlEvents:UIControlEventTouchUpInside];
    
    
    //添加一个遮罩
    self.shadowView = [[UIView alloc]initWithFrame:self.view.frame];
    self.shadowView.backgroundColor = [UIColor blackColor];
    self.shadowView.alpha = 0.5;
    self.shadowView.hidden = YES;
    [self.view addSubview:self.shadowView];
    //添加一个等待进度轮
    self.activity = [[UIActivityIndicatorView alloc]init];
    self.activity.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
    self.activity.color = [UIColor blueColor];
    CGPoint center = self.completeButton.center;
    center.y += 60;
    self.activity.center = center;
    [self.view addSubview:self.activity];
    
    //添加输入框键盘收回事件
    [self.accountText addTarget:self action:@selector(nextTextField) forControlEvents:UIControlEventEditingDidEndOnExit];
    
    [self.passwordText addTarget:self action:@selector(passwordDone) forControlEvents:UIControlEventEditingDidEndOnExit];
    
}

#pragma mark 键盘弹出/退回事件
-(void)nextTextField{
    
    //1.密码有效性性验证
    if (self.accountText.text.length == 0) {
        
        [Tools alertWithTitle:@"温馨提示" andMessage:@"密码不能为空"];
        return;
    }
    [self.passwordText becomeFirstResponder];
}

-(void)passwordDone{
    
    [self.passwordText resignFirstResponder];
}


#pragma mark 点击完成事件
-(void)tapCompleteButton:(UIButton *)sender{
    
    NSLog(@"%s",__func__);
    
}

@end
